<template>
  <view class="content pd-20 pb-40">
    <view class="list-block">
      <u-collapse :value="['workInfo']" ref="workInfo">
        <u-collapse-item title="作业信息" name="workInfo" :border="true">
          <view v-if="serviceType != 'create'" class="item-block mb-30">
            <view class="item-label mb-20">作业证编号:</view>
            <view class="input-block pl-20 pr-20">
              <input class="input" disabled v-model="params.number" placeholder="请输入..." placeholder-class="placeholder"/>
            </view>
          </view>
          <view class="item-block mb-30">
            <view class="item-label mb-20">申请人:</view>
            <view class="input-block pl-20 pr-20">
              <input class="input" disabled v-model="params.applicant" placeholder="请输入..." placeholder-class="placeholder"/>
            </view>
          </view>
          <view class="item-block mb-30">
            <view class="item-label mb-20">申请单位:</view>
            <view class="input-block pl-20 pr-20">
              <input class="input" disabled v-model="params.applicationUnit" placeholder="请输入..." placeholder-class="placeholder"/>
            </view>
          </view>
          <view class="item-block mb-30"  @click="routeByUrl('/pagesCommon/treeList?paramsKey=guardianId')">
            <view class="item-label mb-20"><text class="wraning-icon">*</text>监护人:</view>
            <view class="input-block pl-20 pr-20">
              <input class="input" :disabled="disabled" v-model="params.guardianId" placeholder="请选择" placeholder-class="placeholder"/>
              <u-icon name="arrow-right" color="#999999" size="36rpx"></u-icon>
            </view>
          </view>
          <view class="item-block mb-30">
            <view class="item-label mb-20"><text class="wraning-icon">*</text>作业地点:</view>
            <view class="input-block pl-20 pr-20">
              <input class="input" :disabled="disabled" v-model="params.name" placeholder="请输入..." placeholder-class="placeholder"/>
            </view>
          </view>
          <view class="item-block mb-30">
            <view class="item-label mb-20"><text class="wraning-icon">*</text>动火作业级别:<u-icon name="question-circle" color="#999999" size="30rpx" @click="openToast('1')"></u-icon></view>
            <view class="input-block pl-20 pr-20" @click="openPicker('hotTypeList', 'level')">
              <view v-if="level" class="select-value">{{level}}</view>
              <view v-else>请选择</view>
              <u-icon name="arrow-right" color="#999999" size="36rpx"></u-icon>
            </view>
          </view>
          <view class="item-block mb-30">
            <view class="item-label mb-20"><text class="wraning-icon">*</text>动火方式:</view>
            <!-- <view class="input-block pl-20 pr-20">
              <input class="input" :disabled="disabled" v-model="params.way" placeholder="请输入..." placeholder-class="placeholder"/>
            </view> -->
            <!-- <view class="input-block pl-20 pr-20" @click="openPicker('wayList', 'way')">
              <view v-if="params.way" class="select-value">{{params.way}}</view>
              <view v-else>请选择</view>
              <u-icon name="arrow-right" color="#999999" size="36rpx"></u-icon> 
            </view>-->
            <u-checkbox-group
              :disabled="disabled"
              size="15px"
              @change="checkboxChange2"
              v-model="checkboxValue3"
              placement="row">
              <u-checkbox
                labelSize="14px"
                :customStyle="{marginBottom: '10px'}"
                v-for="(item, index) in wayList"
                :key="index"
                :label="item.label"
                :name="item.value"
              ></u-checkbox>
            </u-checkbox-group>
          </view>
          <view class="item-block mb-30">
            <view class="item-label mb-20"><text class="wraning-icon">*</text>动火内容:</view>
            <view class="input-block pl-20 pr-20">
              <input class="input" :disabled="disabled" v-model="params.content" placeholder="请输入..." placeholder-class="placeholder"/>
            </view>
          </view>
          <view class="item-block mb-30">
            <view class="item-label mb-20"><text class="wraning-icon">*</text>动火开始时间:<u-icon name="question-circle" color="#999999" size="30rpx" @click="openToast('2')"></u-icon></view>
            <view class="input-block pl-20 pr-20" style="justify-content: flex-start;" @click="openDateTimePicker('startTime')">
              <u-icon name="calendar" color="#999999" size="36rpx"></u-icon>
              <view v-if="params.startTime" class="select-value ml-10">{{params.startTime}}</view>
              <view v-else class="ml-10">请选择</view>
            </view>
          </view>
          <view v-if="params.startTime" class="item-block mb-30">
            <view class="item-label mb-20"><text class="wraning-icon">*</text>动火结束时间:<u-icon name="question-circle" color="#999999" size="30rpx" @click="openToast('2')"></u-icon></view>
            <view class="input-block pl-20 pr-20" style="justify-content: flex-start;" @click="openDateTimePicker('endTime')">
              <u-icon name="calendar" color="#999999" size="36rpx"></u-icon>
              <view v-if="params.endTime" class="select-value ml-10">{{params.endTime}}</view>
              <view v-else class="ml-10">请选择</view>
            </view>
          </view>
          <view class="item-list" v-for="(item, index) in paramsPersonList" :key="index">
            <view v-if="!disabled" class="position-icon"><u-icon v-if="index > 0" name="close-circle-fill" color="#FE0303" size="36rpx" @click="deleteItem('workInfo', 'paramsPersonList', index)"></u-icon></view>
            <view class="item-block mb-30">
              <view class="item-label mb-20"><text class="wraning-icon">*</text>动火人:</view>
              <view class="input-block pl-20 pr-20">
                <input class="input" :disabled="disabled" v-model="item.workerName" placeholder="请输入..." placeholder-class="placeholder"/>
              </view>
            </view>
            <view class="image-block mb-30">
              <view class="image-title"><text class="wraning-icon">*</text>动火人资格证书</view>
              <u-upload :disabled="disabled" :fileList="item.certification" @afterRead="afterRead" @delete="deletePic" :name="JSON.stringify({paramsKey: 'paramsPersonList', keyName: 'certification', index})"></u-upload>
            </view>
          </view>
          <view v-if="!disabled" class="button-block mt-20">
            <button class="button" @click="addItem('workInfo', 'paramsPersonList')"><u-icon name="plus" color="#FFFFFF" size="30rpx"></u-icon><view class="ml-30">添加动火人</view></button>
          </view>
          <view class="item-block mt-30">
            <view class="item-label mb-20">涉及的其他特殊作业:</view>
            <u-checkbox-group
            :disabled="disabled"
              size="15px"
              @change="checkboxChange1"
              v-model="checkboxValue2"
              placement="row">
              <u-checkbox
              labelSize="14px"
                :customStyle="{marginBottom: '10px'}"
                v-for="(item, index) in specialWorkList"
                :key="index"
                :label="item.label"
                :name="item.value"
              ></u-checkbox>
            </u-checkbox-group>
            <!-- <view class="input-block pl-20 pr-20" @click="openPicker('specialWorkList', 'otherLicence')">
              <view v-if="params.otherLicenceName" class="select-value">{{params.otherLicenceName}}</view>
              <view v-else>请选择</view>
              <u-icon v-if="!params.otherLicenceName" name="arrow-right" color="#999999" size="36rpx"></u-icon>
              <u-icon v-else name="close-circle-fill" color="#999999" size="36rpx" @click.native.stop="clearOtherLicenceName"></u-icon>
            </view> -->
          </view>
          <view class="item-block mt-30">
            <view class="item-label mb-20"><text class="wraning-icon">*</text>风险辨识结果:</view>
            <!-- <SELECT @itemclick="cpnClick" :search="search"/> -->
            <u-checkbox-group
            :disabled="disabled"
              size="15px"
              @change="checkboxChange"
              v-model="checkboxValue1"
              placement="row">
              <u-checkbox
              labelSize="14px"
                :customStyle="{marginBottom: '10px'}"
                v-for="(item, index) in checkboxList1"
                :key="index"
                :label="item.name"
                :name="item.value"
              ></u-checkbox>
            </u-checkbox-group>
            <!-- <view class="input-block pl-20 pr-20">
              <input class="input" :disabled="disabled" v-model="params.identificationResult" placeholder="请输入..." placeholder-class="placeholder" @click="routeByUrls('/pagesWork/Standardofcasualtyclassification')"/>
            </view> -->
          </view>
        </u-collapse-item>
      </u-collapse>
    </view>
    <view class="list-block mt-20">
      <u-collapse :value="['dataInfo']" ref="dataInfo" v-if="paramsAnalyzeDataList.length">
        <u-collapse-item title="动火分析数据" name="dataInfo" :border="true">
          <view class="item-list" v-for="(item, index) in paramsAnalyzeDataList" :key="index">
            <view v-if="!disabled" class="position-icon"><u-icon v-if="index > 0" name="close-circle-fill" color="#FE0303" size="36rpx" @click="deleteItem('dataInfo', 'paramsAnalyzeDataList', index)"></u-icon></view>
            <view class="item-block mb-30" @click="openDateTimePicker('createTime', 'list', 'paramsAnalyzeDataList', index, (!unPushState && index >= oldAnalyzeDataListLength))">
              <view class="item-label mb-20"><text class="wraning-icon" v-show="params.level == 2 || params.level == 3 ">*</text>第{{index + 1}}次动火分析时间:</view>
              <view class="input-block pl-20 pr-20" style="justify-content: flex-start;">
                <u-icon name="calendar" color="#999999" size="36rpx"></u-icon>
              <view v-if="item.createTime" class="select-value ml-10">{{item.createTime}}</view>
              <view v-else class="ml-10">请选择</view>
              </view>
            </view>
            <view class="item-block mb-30">
              <view class="item-label mb-20"><text class="wraning-icon" v-show="params.level == 2 || params.level == 3 ">*</text>分析数据(%LEL):</view>
              <view class="input-block pl-20 pr-20">
                <input class="input" :disabled="unPushState" v-model="item.analyzeData" placeholder="请输入..." placeholder-class="placeholder"/>
              </view>
            </view>
            <view class="image-block mb-30">
              <view class="image-title"><text class="wraning-icon" v-show="params.level == 2 || params.level == 3 ">*</text>分析数据图片</view>
              <u-upload :disabled="unPushState" :fileList="item.photo" :capture="['camera']" @afterRead="afterRead" @delete="deletePic" :name="JSON.stringify({paramsKey: 'paramsAnalyzeDataList', keyName: 'photo', index})" :maxCount="1"></u-upload>
            </view>
            <view class="item-block mb-30">
              <view class="item-label mb-20"><text class="wraning-icon" v-show="params.level == 2 || params.level == 3 ">*</text>分析人:</view>
              <view class="input-block pl-20 pr-20">
                <input class="input" :disabled="unPushState" v-model="item.analyst" placeholder="请输入..." placeholder-class="placeholder"/>
              </view>
            </view>
          </view>
          <view v-if="!unPushState" class="button-block mt-20">
            <button class="button" @click="addItem('dataInfo', 'paramsAnalyzeDataList')"><u-icon name="plus" color="#FFFFFF" size="30rpx"></u-icon><view class="ml-30">添加动火分析数据</view></button>
          </view>
        </u-collapse-item>
      </u-collapse>
    </view>
    <view class="list-block mt-20">
      <u-collapse :value="['safeInfo']" ref="safeInfo">
        <u-collapse-item title="安全措施" name="safeInfo" :border="true">
          <view class="item-list mb-30" v-for="(item, index) in paramsSafeInfoList" :key="index">
            <view v-if="item.state" class="radio-block">
              <view v-if="item.equipmentJson" class="input-list">
                <view class="radio-title mb-30">{{index + 1}}.设备数量:</view>
                <view class="input-block pt-20 pb-20 pl-50 pr-50 border-b-common" v-for="(child, ind) in item.equipmentJson">
                  <view class="input-label">{{child.label}}</view>
                  <input class="input text-r" :disabled="disabled" v-model="child.value" placeholder="请输入..." placeholder-class="placeholder"/>
                </view>
                <view class="image-block mt-30">
                  <view class="image-title">拍照</view>
                  <u-upload :disabled="disabled" :fileList="item.photo" :capture="['camera']" @afterRead="afterRead" @delete="deletePic" :name="JSON.stringify({paramsKey: 'paramsSafeInfoList', keyName: 'photo', index})"></u-upload>
                </view>
              </view>
              <view v-else class="item-block mb-30">
                <view class="item-label mb-20">{{index + 1}}.其他需要补充的安全措施:</view>
                <view class="input-block pl-20 pr-20">
                  <input class="input" :disabled="disabled" v-model="item.content" placeholder="请输入..." placeholder-class="placeholder"/>
                </view>
              </view>
            </view>
            <view v-else class="radio-block">
              <view class="radio-title mb-30">{{index + 1}}.{{item.content}}</view>
              <u-radio-group :disabled="disabled" placement="row" :value="item.radioStatus" @change="radioChange(index, $event)">
                <u-radio activeColor="#00B930" label="合格" name="合格"></u-radio>
                <u-radio activeColor="#FE1515" label="不合格" name="不合格"></u-radio>
                <u-radio activeColor="#FCA22C" label="不适用" name="不适用"></u-radio>
              </u-radio-group>
              <view class="image-block mt-30">
                <view class="image-title">拍照</view>
                <u-upload :disabled="disabled" :fileList="item.photo" :capture="['camera']" @afterRead="afterRead" @delete="deletePic" :name="JSON.stringify({paramsKey: 'paramsSafeInfoList', keyName: 'photo', index})"></u-upload>
              </view>
            </view>
          </view>
        </u-collapse-item>
      </u-collapse>
    </view>
    <view class="list-block mt-20">
      <u-collapse :value="['personInfo']" ref="personInfo">
        <u-collapse-item title="人员信息" name="personInfo" :border="true">
          <view class="item-block mb-30">
            <view class="item-label mb-20">安全交底人:</view>
            <view class="input-block pl-20 pr-20">
              <input class="input" disabled v-model="params.applicant" placeholder="请输入..." placeholder-class="placeholder"/>
            </view>
          </view>
          <view class="info-block mb-30" v-for="(item, index) in paramsPersonList" :key="index">
            <view class="item-label"><text class="wraning-icon">*</text>接受交底人:</view>
            <view v-if="!disabled" class="right-block" @click="routeByUrl(`/pagesCommon/autoGraph?paramsKey=paramsPersonList&type=list&keyName=signature&index=${index}`)">
              <text v-if="!item.signature">签章({{item.workerName}})</text>
              <image v-else class="image" :src="item.signature"></image>
            </view>
            <view v-else class="right-block">
              <text v-if="!item.signature">签章({{item.workerName}})</text>
              <image v-else class="image" :src="item.signature"></image>
            </view>
          </view>
          <view class="info-block mb-30">
            <view class="item-label"><text class="wraning-icon">*</text>监护人:</view>
            <view v-if="!disabled" class="right-block" @click="routeByUrl(`/pagesCommon/autoGraph?paramsKey=guardian`)">
              <text v-if="!params.guardian">签章({{params.guardianId ? params.guardianId : ''}})</text>
              <image v-else class="image" :src="params.guardian"></image>
            </view>
            <view v-else class="right-block">
              <text v-if="!params.guardian">签章({{params.guardianId ? params.guardianId : ''}})</text>
              <image v-else class="image" :src="params.guardian"></image>
            </view>
          </view>
        </u-collapse-item>
      </u-collapse>
    </view>
    
    <view class="list-block mt-20">
      <u-collapse :value="['checkInfo']" ref="checkInfo">
        <u-collapse-item title="审核人员信息" name="checkInfo" :border="true">
          <view class="item-block mb-30" @click="routeByUrl('/pagesCommon/treeList?paramsKey=licensor')">
            <view class="item-label mb-20"><text class="wraning-icon">*</text>许可人:
              <view v-if="serviceType != 'create' && serviceType != 'update'" class="check-state-block">
                <text v-if="checkList[0].status == -1" style="color: #2979ff;">(未审核)</text>
                <text v-if="checkList[0].status == 0" style="color: #ff9900;">(审核中)</text>
                <text v-if="checkList[0].status == 1" style="color: #19be6b;">(审核通过)</text>
                <text v-if="checkList[0].status == 2" style="color: #fa3534;">(已驳回)</text>
              </view>
            </view>
            <view class="input-block pl-20 pr-20">
              <view v-if="params.licensor" class="select-value">{{params.licensor}}</view>
              <view v-else>请选择</view>
              <u-icon name="arrow-right" color="#999999" size="36rpx"></u-icon>
            </view>
            <view v-if="checkList[0].status == 2" class="warning-text mt-10">*驳回原因：{{checkList[0].reasonOfReject}}</view>
          </view>
          <view class="item-block mb-30" @click="routeByUrl('/pagesCommon/treeList?paramsKey=signer')">
            <view class="item-label mb-20"><text class="wraning-icon">*</text>签发人:
              <view v-if="serviceType != 'create' && serviceType != 'update' && checkList[0].status == 1" class="check-state-block">
                <text v-if="checkList[1].status == -1" style="color: #2979ff;">(未审核)</text>
                <text v-if="checkList[1].status == 0" style="color: #ff9900;">(审核中)</text>
                <text v-if="checkList[1].status == 1" style="color: #19be6b;">(审核通过)</text>
                <text v-if="checkList[1].status == 2" style="color: #fa3534;">(已驳回)</text>
              </view>
            </view>
            <view class="input-block pl-20 pr-20">
              <view v-if="params.signer" class="select-value">{{params.signer}}</view>
              <view v-else>请选择</view>
              <u-icon name="arrow-right" color="#999999" size="36rpx"></u-icon>
            </view>
            <view v-if="checkList[1].status == 2" class="warning-text mt-10">*驳回原因：{{checkList[1].reasonOfReject}}</view>
          </view>
          <view v-if="params.level == 2 || params.level == 3" class="item-block mb-30" @click="routeByUrl('/pagesCommon/treeList?paramsKey=inCharge')">
            <view class="item-label mb-20"><text class="wraning-icon">*</text>分管负责人:
              <view v-if="serviceType != 'create' && serviceType != 'update' && checkList[1].status == 1" class="check-state-block">
                <text v-if="checkList[2].status == -1" style="color: #2979ff;">(未审核)</text>
                <text v-if="checkList[2].status == 0" style="color: #ff9900;">(审核中)</text>
                <text v-if="checkList[2].status == 1" style="color: #19be6b;">(审核通过)</text>
                <text v-if="checkList[2].status == 2" style="color: #fa3534;">(已驳回)</text>
              </view>
            </view>
            <view class="input-block pl-20 pr-20">
              <view v-if="params.inCharge" class="select-value">{{params.inCharge}}</view>
              <view v-else>请选择</view>
              <u-icon name="arrow-right" color="#999999" size="36rpx"></u-icon>
            </view>
            <view v-if="checkList[2].status == 2" class="warning-text mt-10">*驳回原因：{{checkList[2].reasonOfReject}}</view>
          </view>
          <view v-if="params.level == 3" class="item-block mb-30" @click="routeByUrl('/pagesCommon/treeList?paramsKey=mainInCharge')">
            <view class="item-label mb-20"><text class="wraning-icon">*</text>主要负责人:
              <view v-if="serviceType != 'create' && serviceType != 'update' && checkList[2].status == 1" class="check-state-block">
                <text v-if="checkList[3].status == -1" style="color: #2979ff;">(未审核)</text>
                <text v-if="checkList[3].status == 0" style="color: #ff9900;">(审核中)</text>
                <text v-if="checkList[3].status == 1" style="color: #19be6b;">(审核通过)</text>
                <text v-if="checkList[3].status == 2" style="color: #fa3534;">(已驳回)</text>
              </view>
            </view>
            <view class="input-block pl-20 pr-20">
              <view v-if="params.mainInCharge" class="select-value">{{params.mainInCharge}}</view>
              <view v-else>请选择</view>
              <u-icon name="arrow-right" color="#999999" size="36rpx"></u-icon>
            </view>
            <view v-if="checkList[3].status == 2" class="warning-text mt-10">*驳回原因：{{checkList[3].reasonOfReject}}</view>
          </view>
          <view v-if="serviceType == 'check'" class="info-block mb-30">
            <view class="item-label"><text class="wraning-icon mr-10" style="color: #FF0000;">*</text>审核人({{userInfo.nickname ? userInfo.nickname : '-'}}):</view>
            <view class="right-block" @click="routeByUrl(`/pagesCommon/autoGraph?paramsKey=checkSignature`, true)">
              <text v-if="!checkSignature">签章</text>
              <image v-else class="image" :src="checkSignature"></image>
            </view>
          </view>
        </u-collapse-item>
      </u-collapse>
    </view>
    <view class="list-block mt-20" v-if="params.guardianCheckContent && guardianCheckPhotoList">
      <u-collapse :value="['becompleted']" ref="becompleted">
        <u-collapse-item title="验收完工" name="becompleted" :border="true">
          <view class="item-block mb-30">
            <view class="item-label mb-20">安全措施检查内容:</view>
            <view class="input-block pl-20 pr-20">
              <input class="input" disabled v-model="params.guardianCheckContent" placeholder="请输入..." placeholder-class="placeholder"/>
            </view>
          </view>
          <view class="item-blocks pt-20 pb-20">
            <view class="item-label">验收完工图片:</view>
            <view class="image-list">
              <image v-for="(item, index) in guardianCheckPhotoList" :key="index" class="image" mode="aspectFill" :src="item.url" @click="previewImage(item.url)"></image>
            </view>
          </view>
        </u-collapse-item>
      </u-collapse>
    </view>
    <view v-if="serviceType == 'create' || serviceType == 'update'" class="button-block mt-50">
      <button class="button-cancel" @click="$u.throttle(save, 1000)">保存草稿</button>
      <button class="button-submit" @click="$u.throttle(submit, 1000)">提交审核</button>
    </view>
    <view v-if="serviceType == 'check'" class="button-block mt-50">
      <button v-if="guardianAuditState" class="button-success" @click="$u.throttle(finish, 1000)">验收完工</button>
      <button v-if="!guardianAuditState" class="button-cancel" @click="$u.throttle(cancel, 1000)">驳回</button>
      <button v-if="!guardianAuditState" :class="[confirmdisabled?'button-cancel ':'button-submit']" :disabled="confirmdisabled" @click="$u.throttle(confirm, 1000)">通过</button>
    </view>
    <view v-if="serviceType == 'push'" class="button-block mt-50" style="justify-content: center;">
      <button class="button-success" @click="$u.throttle(pushAnalyzeData, 1000)">追加数据</button>
    </view>
    <u-picker :show="pickerState" :columns="pickerList" keyName="label" :closeOnClickOverlay="true" @confirm="pickerConfirm" @close="() => pickerState = false" @cancel="() => pickerState = false"></u-picker>
    <u-datetime-picker :show="startTimeState" v-model="defaultDateTime" :minDate="nowDate" mode="datetime" :closeOnClickOverlay="true" @confirm="dateTimeConfirm('startTime', $event)" @close="() => startTimeState = false" @cancel="() => startTimeState = false"></u-datetime-picker>
    <u-datetime-picker :show="endTimeState" v-model="defaultDateTime" :minDate="nowDate"   mode="datetime" :closeOnClickOverlay="true" @confirm="dateTimeConfirm('endTime', $event)" @close="() => endTimeState = false" @cancel="() => endTimeState = false"></u-datetime-picker>

    <!-- <u-datetime-picker :show="endTimeState" v-model="defaultDateTime" :minDate="minDate" :maxDate="maxDate" mode="datetime" :closeOnClickOverlay="true" @confirm="dateTimeConfirm('endTime', $event)" @close="() => endTimeState = false" @cancel="() => endTimeState = false"></u-datetime-picker> -->
    <u-datetime-picker :show="createTimeState" v-model="defaultDateTime" mode="datetime" :closeOnClickOverlay="true" @confirm="dateTimeConfirm('createTime', $event)" @close="() => createTimeState = false" @cancel="() => createTimeState = false"></u-datetime-picker>
    <u-modal :show="cancelState"  title="驳回原因" :showCancelButton="true" @confirm="cancelConfirm" @cancel="() => cancelState = false" @close="() => cancelState = false">
      <view class="slot-content">
        <textarea class="text-area" v-model="reasonForRejection" placeholder="请输入驳回原因" placeholder-class="text-area-placeholder"></textarea>
      </view>
    </u-modal>
    <u-popup :show="toastState" mode="center" :closeOnClickOverlay="true" round="10rpx" :customStyle="{overflow: 'hidden'}" @close="() => toastState = false">
      <view class="toast-block pd-20">
        <view v-if="toastType == 1" class="toast mb-10">特级动火作业：是指在运行状态下的易燃易爆生产装置的设备、管道、储罐等部位上及其他特殊危险场所进行的动火作业。带压不置换动火作业按特殊动火作业管理；易燃易爆危险化学品一、二级重大危险源罐区、易燃易爆危险化学品仓储经营企业构成重大危险源的罐区动火作业全部按特级动火进行管理。</view>
        <view v-if="toastType == 1" class="toast mb-10">一级动火作业：在易燃易爆场所进行的除特级动火作业以外的动火作业，厂区管廊上的动火作业按一级动火作业管理。</view>
        <view v-if="toastType == 1" class="toast">二级动火作业：除特级动火作业和一级动火作业以外的动火作业。凡生产装置或系统全部停车，装置经清洗、置换、分析合格并采取安全隔离措施后，可根据其火灾、爆炸危险性大小，经所在单位安全管理负责人批准，动火作业可按二级动火作业管理。</view>
        <view v-if="toastType == 2" class="toast">特级动火、一级动火作业的安全作业证有效期不应超过 8h；二级动火作业的安全作业证有效期不应超过 72h。</view>
      </view>
    </u-popup>
    <u-popup :show="popupState" mode="center" round="6rpx" @close="popupClose">
      <view class="popup-block">
        <view class="popup-title mb-30">安全措施检查内容
          <input class="inputcss" v-model="guardianCheckContent" type="text">
        </view>
        <u-upload :action="action" multiple :max-count="3" :capture="['camera']" :file-list="fileLists" @afterRead="aftesrReads" @delete="deleteImage"></u-upload>
        <view class="button-block mt-50">
          <u-button type="info" text="取消" :custom-style="{width: '250rpx', backgroundColor: '#FFFFFF !important'}" @click="popupClose()"></u-button>
          <u-button type="primary" text="提交" :custom-style="{width: '250rpx'}" @click="submitPhoto"></u-button>
        </view>
      </view>
    </u-popup>
  </view>
</template>

<script>
  import { createWorkInfoApi, getWorkDetailApi, checkWorkInfoApi, updateWorkInfoApi, pushAnalyzeDataApi, getCheckInfoApi, finishWorkInfoApi } from '@/apis/work/index.js'
  import { getDictListApi, getSpecialWorkListApi, getSafeInfoListApi } from '@/apis/work/common.js'
  import { getToken, getUserInfo } from '@/utils/auth.js'
  import dayjs from 'dayjs'
  import SELECT from '../pagesWork/Standardofcasualtyclassification.vue'
  

  export default {  
    // components:{
    //   SELECT,
    // },
    data() {
      return {
        checkboxValue3:[],
        checkboxValue2:[],
        checkboxValue1:[],
        checkboxList1: [
          {
            name: '物体打击',
            value: '1'
          },
          {
            name: '车辆伤害',
            value: '2'
          },
          {
            name: '机械伤害',
            value: '3'
          },
          {
            name: '起重伤害',
            value: '4'
          },
          {
            name: '触电',
            value: '5'
          },
          {
            name: '淹溺',
            value: '6'
          },
          {
            name: '灼烫',
            value: '7'
          },
          {
            name: '火灾',
            value: '8'
          },
          {
            name: '高处坠落',
            value: '9'
          },
          {
            name: '坍塌',
            value: '10'
          },
          {
            name: '冒顶片帮',
            value: '11'
          },
          {
            name: '透水',
            value: '12'
          },
          {
            name: '放炮',
            value: '13'
          },
          {
            name: '火药爆炸',
            value: '14'
          },
          {
            name: '瓦斯爆炸',
            value: '15'
          },
          {
            name: '锅炉爆炸',
            value: '16'
          },
          {
            name: '容器爆炸',
            value: '17'
          },
          {
            name: '其它爆炸',
            value: '18'
          },
          {
            name: '中毒和窒息',
            value: '19'
          },
          {
            name: '其它伤害',
            value: '20'
          },
        ],
        search:'',
        guardianCheckPhotoList:[],
        guardianCheckContent:'',
        action: this.uploadImageUrl,
        guardianCheckPhoto:[],
        fileLists: [],
        popupState: false,
        confirmdisabled:false,
        disable:[],
        toastType: '',
        toastState: false,
        serviceType: 'create',
        allDisabled: false,
        disabled: false,
        unPushState: false,
        cancelState: false,
        reasonForRejection: '',
        params: {
          type: ''
        },
        paramsPersonList: [
          { workerName: '', certification: [] }
        ],
        paramsAnalyzeDataList: [
          { createTime: '', analyzeData: '', photo: [], analyst: '' }
        ],
        wayList: [
          { label: '焊接', value: '1' },
          { label: '切割', value: '2' },
          { label: '其它', value: '3' }
        ],
        pickerState: false,
        startTimeState: false,
        endTimeState: false,
        createTimeState: false,
        pickerList: [],
        hotTypeList: [],
        specialWorkList: [],
        paramsSafeInfoList: [],
        // 页面展示字段
        pickerName: '',
        dateTimeName: '',
        level: '',
        defaultDateTime: dayjs().format('YYYY-MM-DD HH:mm'),
        nowDate: dayjs().valueOf(),
        minDate: '',
        maxDate: '',
        oldAnalyzeDataListLength: 0,
        checkSignature: '',
        checkList: [],
        userInfo: {},
        guardianAuditState: false
      }
    },
    onLoad(options) {
      if(options.serviceType) {
        // console.log(options)
        this.serviceType = options.serviceType
        if(options.serviceType == 'detail') {
          this.disabled = true
          this.unPushState = true
          this.allDisabled = true
        }
        if(options.serviceType == 'check') {
          this.disabled = true
          this.unPushState = true
          this.allDisabled = true
        }
        if(options.serviceType == 'push') {
          this.disabled = true
          this.allDisabled = true
        }
        if(options.serviceType != 'create') uni.setNavigationBarTitle({ title: '动火作业票' })
      }
      if(options.guardianAudit) {
        this.guardianAuditState = options.guardianAudit == 1 ? true : false
      }
      if(options.type) this.params.type = parseInt(options.type)
      if(getUserInfo()) {
        let userInfo = getUserInfo()
        console.log(userInfo)
        if(this.serviceType == 'create') {
          var map = {
            nickname:userInfo.nickname,
            id:userInfo.id,
            keys:'1'
          }
          this.disable.splice(0,1,map)
          console.log(this.disable)
          Object.assign(this.params, { applicant: userInfo.nickname, applicationUnit: userInfo.dept.name})
        } else {
          this.userInfo = userInfo
        }
      }
      this.getHotTypeList()
      this.getSpecialWorkList()
      if(!options.id) this.getSafeInfoList({type: options.type})
      if(options.id) this.getWorkDetail({ id: options.id })
    },
    onShow() {

      this.paramsPersonList = JSON.parse(JSON.stringify(this.paramsPersonList))
      this.params = JSON.parse(JSON.stringify(this.params))
    },
    created(){
      this.params.createTime =  dayjs().format('YYYY-MM-DD HH:mm:ss')
      console.log(this.params.createTime)
    },
    methods: {
      checkboxChange2(item){
        console.log(item)
        this.params.way = item
        console.log(this.params)
      },
      checkboxChange1(item){
        console.log(item)
        this.params.otherLicenceName = item
        console.log(this.params)
      },
      checkboxChange(item){
        console.log(item)
        this.params.identificationResult = item
        console.log(this.params)
      },
      cpnClick(item) {
          //处理事件
        console.log('cpnClick', item);
        this.params.identificationResult = item
        console.log(this.params)
      },
      submitPhoto(){
        if(this.guardianCheckContent == ''||this.guardianCheckPhoto.length == 0){
          uni.showToast({ title: '请上传安全措施检查内容和图片', icon: 'none' })
          return;
        }
        let topo = JSON.stringify(this.guardianCheckPhoto)
        let map = {
          id:this.params.id,
          guardianCheckPhoto:topo,
          guardianCheckContent:this.guardianCheckContent
        }
        finishWorkInfoApi(map).then(res => {
          uni.showToast({ title: '已结束', icon: 'none' })
          setTimeout(() => uni.navigateBack(), 500)
        }).catch(err => console.warn(err))
      },
      async aftesrReads(event) {
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        let lists = [].concat(event.file)
        let fileListLen = this.fileLists.length
        lists.map((item) => {
          this.fileLists.push({
            ...item,
            status: 'uploading',
            message: '上传中'
          })
        })
        for (let i = 0; i < lists.length; i++) {
          const result = await this.uploadFilePromises(lists[i].url)
          let item = this.fileLists[fileListLen]
          if(result.status == 'success') {
            this.fileLists.splice(fileListLen, 1, Object.assign(item, {
              status: result.status,
              message: '',
              url: result.url
            }))
            fileListLen++
          } else {
            this.fileLists.splice(fileListLen, 1)
          }
        }
      },
      uploadFilePromises(url) {
        return new Promise((resolve, reject) => {
          let a = uni.uploadFile({
            url: this.uploadImageUrl,
            filePath: url,
            name: 'file',
            formData: {
              user: 'test'
            },
            header: {
              'Authorization': `Bearer ${getToken()}`,
              'tenant-id':  '1'
            },
            success: (res) => {
              console.log(res)
              let result = JSON.parse(res.data)
              console.log(result)
              if (result.code == 0) {
                this.guardianCheckPhoto.push(result.data)
                console.log(this.guardianCheckPhoto)
                resolve({url: result.data.url, status: 'success'})
              } else {
                uni.showToast({ title: 'OSS服务器错误', icon: 'none' })
                resolve({url, status: 'fail'})
              }
            },
            fail: () => uni.showToast({ title: '图片上传失败', icon: 'none' })
          })
        })
      },
      deleteImage: function(event) {
        this.guardianCheckPhoto.splice(event.index, 1)
        this.fileLists.splice(event.index, 1)
      },
      popupClose: function() {
		    this.guardianCheckPhoto = []
        this.popupState = false
      },
      submit: function() {
        this.createWorkInfo(true)
      },
      save: function() {
        this.createWorkInfo(false)
      },
      cancel: function() {
        this.cancelState = true
      },
      radioChange: function(index, event) {
        this.paramsSafeInfoList[index].radioStatus = event
      },
      clearOtherLicenceName: function(event) {
        let params = JSON.parse(JSON.stringify(this.params))
        delete params.otherLicenceName
        this.params = params
        event.stopPropagation()
      },
      cancelConfirm: function() {
        if(!this.checkSignature) {
          uni.showToast({  title: '审核人员未签章', icon: 'none' })
          return false
        }
        if(!this.reasonForRejection) {
          uni.showToast({  title: '请输入驳回原因', icon: 'none' })
          return false
        }
        let params = { licenceId: this.params.id, submit: false, reasonForRejection: this.reasonForRejection, signature: this.checkSignature }
        this.checkWorkInfo(params)
      },
      confirm: function() {
        if(!this.checkSignature) {
          uni.showToast({  title: '审核人员未签章', icon: 'none' })
          return false
        }
        let params = { licenceId: this.params.id, submit: true, signature: this.checkSignature }
        this.checkWorkInfo(params)
        this.confirmdisabled = true
      },
      finish: function() {
        if(!this.checkSignature) {
          uni.showToast({  title: '审核人员未签章', icon: 'none' })
          return false
        }
        this.popupState = true
      },
      createWorkInfo: function(submitState) {
        let params = JSON.parse(JSON.stringify(this.params))
        
        params.guardianName = params.guardianIdId
        console.log(this.paramsAnalyzeDataList)
        console.log(this.params)
        let personList = JSON.parse(JSON.stringify(this.paramsPersonList))
        let analyzeDataList = JSON.parse(JSON.stringify(this.paramsAnalyzeDataList))
        let safeMeasuresList = JSON.parse(JSON.stringify(this.paramsSafeInfoList))
        if(submitState) if(!this.authFormData()) return false
        if(params.startTime) Object.assign(params, { startTime: dayjs(params.startTime).format('YYYY-MM-DD HH:mm:ss')})
        if(params.endTime) Object.assign(params, { endTime: dayjs(params.endTime).format('YYYY-MM-DD HH:mm:ss')})
        personList.map(item => {
          let imageList = []
          if(item.certification && item.certification.length > 0) item.certification.map(child => imageList.push(child.url))
          Object.assign(item, { certification: imageList.toString()})
        })
        analyzeDataList.map(item => {
          let imageList = []
          if(item.photo && item.photo.length > 0) item.photo.map(child => imageList.push(child.url))
          Object.assign(item, { photo: imageList.toString(), createTime: item.createTime ? dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss') : ''})
        })
        safeMeasuresList.map(item => {
          if(item.state) {
            if(item.equipmentJson) Object.assign(item, { equipmentJson: JSON.stringify(item.equipmentJson) })
            if(item.photo && item.photo.length > 0) {
              let imageList = []
              item.photo.map(child => imageList.push(child.url))
              Object.assign(item, { photo: imageList.toString()})
            } else {
              Object.assign(item, { photo: ''})
            }
          } else {
            let imageList = []
            if(item.photo && item.photo.length > 0) item.photo.map(child => imageList.push(child.url))
            Object.assign(item, { photo: imageList.toString()})
            if(item.radioStatus) {
              if(item.radioStatus == '合格' || item.radioStatus == '不合格') Object.assign(item, { qualified: item.radioStatus == '合格' ? true : false})
              if(item.radioStatus == '不适用') Object.assign(item, { applicable: false})
              delete item.radioStatus
            } else {
              Object.assign(item, { qualified: false })
            }
          }
        })
        console.log(analyzeDataList)
        if(analyzeDataList.length == 0){
          console.log('meiypu')
          Object.assign(params, { submit: submitState, levelLabel: this.level, personList, safeMeasuresList })
        }else if(analyzeDataList[0].createTime == ''){
           console.log('有')
          Object.assign(params, {analyzeDataList:analyzeDataList, submit: submitState, levelLabel: this.level, personList, safeMeasuresList })
        }else{
          Object.assign(params, {analyzeDataList:analyzeDataList, submit: submitState, levelLabel: this.level, personList, safeMeasuresList })
        }
        // if(analyzeDataList[0].createTime){
        //   console.log('有')
        //   Object.assign(params, {analyzeDataList:analyzeDataList, submit: submitState, levelLabel: this.level, personList, safeMeasuresList })
        // }
        // else{
        //   console.log('meiypu')
        //   Object.assign(params, { submit: submitState, levelLabel: this.level, personList, safeMeasuresList })
        // }
        
        // console.log(params,'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
        if (typeof params.identificationResult !== 'string') {
          console.log('不是string')
         params.identificationResult = JSON.stringify(params.identificationResult)
        }
        if (typeof params.otherLicenceName !== 'string') {
         params.otherLicenceName = JSON.stringify(params.otherLicenceName)
        }
        if (typeof params.way !== 'string') {
         params.way = JSON.stringify(params.way)
        }
        console.log(params,'111111111111111111111111')
        if(params.id) {
          updateWorkInfoApi(params).then(res => {
            uni.showToast({ title: '提交成功', icon: 'none' })
            setTimeout(() => uni.navigateBack(), 500)
          }).catch(err => console.warn(err))
        } else {
          createWorkInfoApi(params).then(res => {
            uni.showToast({ title: '提交成功', icon: 'none' })
            setTimeout(() => uni.navigateBack(), 500)
          }).catch(err => console.warn(err))
        }
      },
      previewImage: function(url) {
        uni.previewImage({ urls: [url] })
      },
      getWorkDetail: function(params) {
        getWorkDetailApi(params).then(res => {
          if(this.serviceType != 'create' && this.serviceType != 'update' && this.serviceType != 'update') this.getCheckInfo({ licenceId: res.id })
          if(res.guardianCheckPhoto){
            this.guardianCheckPhotoList = JSON.parse(res.guardianCheckPhoto)
            console.log(this.guardianCheckPhotoList)
          }
          let params = JSON.parse(JSON.stringify(res))
          console.log(params)
          this.checkboxValue1 = JSON.parse(params.identificationResult)
          if(params.otherLicenceName){
            this.checkboxValue2 = JSON.parse(params.otherLicenceName)
          }
          if(params.way){
            this.checkboxValue3 = JSON.parse(params.way)
          }
          console.log(this.search)
          this.allDisabled = params.editable && this.serviceType == 'update' ? false : true
          let paramsPersonList = res.personList && res.personList.length > 0 ? JSON.parse(JSON.stringify(res.personList)) : []
          let paramsAnalyzeDataList = res.analyzeDataList && res.analyzeDataList.length > 0 ? JSON.parse(JSON.stringify(res.analyzeDataList)) : []
          let paramsSafeInfoList = res.safeMeasuresList && res.safeMeasuresList.length > 0 ? JSON.parse(JSON.stringify(res.safeMeasuresList)) : []
          paramsPersonList.map(item => {
            let list = []
            let imageList = item.certification ? item.certification.split(',') : []
            imageList.map(child => list.push({ url: child, status: 'success', message: ''}))
            Object.assign(item, { certification: list })
          })
          paramsAnalyzeDataList.map(item => {
            let list = []
            let imageList = item.photo ? item.photo.split(',') : []
            imageList.map(child => list.push({ url: child, status: 'success', message: ''}))
            Object.assign(item, { photo: list })
          })
          paramsSafeInfoList.map(item => {
            if(item.state) {
              if(item.equipmentJson) {
                let list = []
                let imageList = item.photo ? item.photo.split(',') : []
                imageList.map(child => list.push({ url: child, status: 'success', message: ''}))
                Object.assign(item, { photo: list, equipmentJson: JSON.parse(item.equipmentJson) })
              }
            } else {
              let list = []
              let imageList = item.photo ? item.photo.split(',') : []
              imageList.map(child => list.push({ url: child, status: 'success', message: ''}))
              Object.assign(item, { photo: list, radioStatus: item.applicable === false ? '不适用' : item.qualified === true ? '合格' : '不合格' })
              delete item.qualified
              delete item.applicable
            }
          })
          if(params.personList) delete params.personList
          if(params.analyzeDataList) delete params.analyzeDataList
          if(params.safeMeasuresList) delete params.safeMeasuresList
          delete params.submitState
          this.params = params
          this.paramsPersonList = paramsPersonList
          this.paramsAnalyzeDataList = paramsAnalyzeDataList
          console.log(this.paramsAnalyzeDataList,'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
          this.paramsSafeInfoList = paramsSafeInfoList
          this.level = params.level == 1 ? '二级动火' : params.level == 2 ? '一级动火' : '特殊动火'
          this.oldAnalyzeDataListLength = res.analyzeDataList ? res.analyzeDataList.length : 0
          this.$nextTick(() => {
            this.$refs['workInfo'].init()
            // this.$refs['dataInfo'].init()
            this.$refs['safeInfo'].init()
            this.$refs['personInfo'].init()
            this.$refs['checkInfo'].init()
          })
        }).catch(err => console.warn(err))
      },
      getCheckInfo: function(params) {
        getCheckInfoApi(params).then(res => {
          this.checkList = res
        }).catch(err => console.warn(err))
      },
      pushAnalyzeData: function() {
        let params = { licenceId: this.params.id }
        let analyzeDataList = JSON.parse(JSON.stringify(this.paramsAnalyzeDataList))
        analyzeDataList.map(item => Object.assign(item, { photo: item.photo[0] ? item.photo[0].url : '', createTime: item.createTime ? dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss') : ''}))
        Object.assign(params, { analyzeDataList })
        pushAnalyzeDataApi(params).then(res => {
          uni.showToast({ title: '提交成功', icon: 'none' })
          setTimeout(() => uni.navigateBack(), 500)
        }).catch(err => console.warn(err))
      },
      getHotTypeList: function() {
        getDictListApi('licence_level').then(res => {
          this.hotTypeList = [res]
        }).catch(err => console.warn(err))
      },
      getSpecialWorkList: function() {
        getDictListApi('licence_type').then(res => {
          let list = []
          if(res.length > 0) res.map(item => {
            if(item.value != this.params.type) list.push(item)
          })
          this.specialWorkList = list
          console.log(this.specialWorkList)
        }).catch(err => console.warn(err))
      },
      getSafeInfoList: function(params) {
        getSafeInfoListApi(params).then(res => {
          let paramsSafeInfoList = [{
            state: true,
            equipmentJson: [
              { label: '消防水带(根)', value: 0 },
              { label: '灭火器(台)', value: 0 },
              { label: '铁锹(把)', value: 0 },
              { label: '石棉布(块)', value: 0 }
            ],
            photo: []
          }]
          res.map(item => {
            Object.assign(item, { radioStatus: '', photo: [], state: false })
            delete item.deptId
            delete item.id
            paramsSafeInfoList.push(item)
          })
          paramsSafeInfoList.push({
            state: true,
            content: ''
          })
          this.paramsSafeInfoList = paramsSafeInfoList
          this.$nextTick(() => {
            this.$refs['safeInfo'].init()
          })
        }).catch(err => console.warn(err))
      },
      checkWorkInfo: function(params) {
        checkWorkInfoApi(params).then(res => {
          this.confirmdisabled = false
          uni.showToast({ title: '审核完成', icon: 'none' })
          setTimeout(() => uni.navigateBack(), 500)
        }).catch(err => console.warn(err))
      },
      openToast: function(type) {
        this.toastType = type
        this.toastState = true
      },
      openPicker: function(listType, name, type = '', keyName = '', index = 0) {
        if(this.disabled) return false
        if(type == 'list') {
          this.pickerListState = true
          this.pickerKeyName = keyName
          this.pickerIndex = index
        }
        this.pickerName = name
        this.pickerList = this[listType]
        this.pickerState = true
        console.log(this.pickerList)
      },
      pickerConfirm: function(event) {
        if(this.pickerListState) {
          this[this.pickerKeyName][this.pickerIndex][this.pickerName] = event.value[0].value
          this[this.pickerKeyName][this.pickerIndex][`${this.pickerName}Name`] = event.value[0].label
        } else {
          if(this.pickerName == 'otherLicence') {
            this.params[`${this.pickerName}Name`] = event.value[0].label
          } else {
            if(this.pickerName == 'level') {
              if(event.value[0].label.indexOf('特殊') > -1 || event.value[0].label.indexOf('一级') > -1) {
                if(this.params.endTime && dayjs(this.params.startTime).add(8, 'hours').valueOf() < dayjs(this.params.endTime).valueOf()) this.params.endTime = ''
                this.maxDate = dayjs(this.params.startTime).add(8, 'hours').valueOf()
              }
            }
            this.params[this.pickerName] = event.value[0].value
            this[this.pickerName] = event.value[0].label
          }
        }
        this.$nextTick(() => {
          this.$refs['checkInfo'].init()
        })
        this.pickerListState = false
        this.pickerState = false
      },
      openDateTimePicker: function(name, type = '', keyName = '', index = 0, changeState = false) {
        if(this.disabled && !changeState) return false
        if(type == 'list') {
          this.dateTimeListState = true
          this.dateTimeKeyName = keyName
          this.dateTimeIndex = index
        }
        this.dateTimeName = name
        this[`${name}State`] = true
      },
      dateTimeConfirm: function(type, event) {
        if(this.dateTimeListState) {
          this[this.dateTimeKeyName][this.dateTimeIndex][this.dateTimeName] = dayjs(event.value).format('YYYY-MM-DD HH:mm')
        } else {
          if(type == 'startTime') {
            if(this.level.indexOf('特殊') > -1 || this.level.indexOf('一级') > -1) {
              if(this.params.endTime && (dayjs(event.value).valueOf() > dayjs(this.params.endTime).valueOf() || dayjs(event.value).add(8, 'hours').valueOf() < dayjs(this.params.endTime).valueOf())) this.params.endTime = ''
              this.minDate = dayjs(event.value).valueOf()
              this.maxDate = dayjs(event.value).add(8, 'hours').valueOf()
            } else {
              if(this.params.endTime && (dayjs(event.value).valueOf() > dayjs(this.params.endTime).valueOf() || dayjs(event.value).add(72, 'hours').valueOf() < dayjs(this.params.endTime).valueOf())) this.params.endTime = ''
              this.minDate = dayjs(event.value).valueOf()
              this.maxDate = dayjs(event.value).add(72, 'hours').valueOf()
            }
          }
          this.params[this.dateTimeName] = dayjs(event.value).format('YYYY-MM-DD HH:mm')
        }
        this.$nextTick(() => {
          this.$refs['workInfo'].init()
        })
        this.dateTimeListState = false
        this[`${type}State`] = false
      },
      addItem: function(refName, keyName) {
        if(keyName == 'paramsPersonList') this[keyName].push({ workerName: '', certification: [] })
        if(keyName == 'paramsAnalyzeDataList') this[keyName].push({ createTime: '', analyzeData: '', photo: [], analyst: '' })
        this.$nextTick(() => {
          this.$refs[refName].init()
          this.$refs['personInfo'].init()
        })
      },
      deleteItem: function(refName, keyName, index) {
        this[keyName].splice(index, 1)
        this.$nextTick(() => {
          this.$refs[refName].init()
          this.$refs['personInfo'].init()
        })
      },
      deletePic(event) {
        if(this.disabled) return false
        let nameObj = JSON.parse(event.name)
        this[nameObj.paramsKey][nameObj.index][nameObj.keyName].splice(event.index, 1)
      },
      async afterRead(event) {
        let lists = [].concat(event.file)
        let nameObj = JSON.parse(event.name)
        let fileListLen = this[nameObj.paramsKey][nameObj.index][nameObj.keyName].length
        lists.map(item => this[nameObj.paramsKey][nameObj.index][nameObj.keyName].push({ ...item, status: 'uploading', message: '上传中' }) )
        for (let i = 0; i < lists.length; i++) {
          const result = await this.uploadFilePromise(lists[i].url)
          let item = this[nameObj.paramsKey][nameObj.index][nameObj.keyName][fileListLen]
          if(result.status == 'success') {
            this[nameObj.paramsKey][nameObj.index][nameObj.keyName].splice(fileListLen, 1, Object.assign(item, { status: result.status, message: '', url: result.url }))
            fileListLen++
          } else {
            this[nameObj.paramsKey][nameObj.index][nameObj.keyName].splice(fileListLen, 1)
          }
        }
        this.$nextTick(() => {
          this.$refs['workInfo'].init()
          // this.$refs['dataInfo'].init()
          this.$refs['safeInfo'].init()
          this.$refs['personInfo'].init()
          this.$refs['checkInfo'].init()
        })
      },
      uploadFilePromise(url) {
        return new Promise((resolve, reject) => {
          let a = uni.uploadFile({
            url: this.uploadImageUrl,
            filePath: url, name: 'file', formData: { "Content-Type": "multipart/form-data" },
            header: { 'Authorization': `Bearer ${getToken()}`, 'tenant-id':  '1' },
            success: res => {
              let result = JSON.parse(res.data)
              if (result.code == 0) {
                resolve({url: result.data.url, status: 'success'})
              } else {
                uni.showToast({ title: 'OSS服务器错误', icon: 'none' })
                resolve({url, status: 'fail'})
              }
            },
            fail: () => uni.showToast({ title: '图片上传失败', icon: 'none' })
          })
        })
      },
      authFormData: function() {
        let params = this.params
        console.log(params.level)
        console.log(params)
        let personList = this.paramsPersonList
        let safeMeasuresList = this.paramsSafeInfoList
        let paramsAnalyzeDataLists = this.paramsAnalyzeDataList
        console.log(paramsAnalyzeDataLists,'2222222222222222222222222222')
        console.log(paramsAnalyzeDataLists[0].createTime)
        if(!params.guardianId) {
          uni.showToast({ title: '请输入监护人名称', icon: 'none' })
          return false
        }
        if(!params.name) {
          uni.showToast({ title: '请输入作业地点', icon: 'none' })
          return false
        }
        if(!params.content) {
          uni.showToast({ title: '请输入动火内容', icon: 'none' })
          return false
        }
        if(!this.level) {
          uni.showToast({ title: '请选择动火作业级别', icon: 'none' })
          return false
        }
        if(!params.way) {
          uni.showToast({ title: '请选择动火方式', icon: 'none' })
          return false
        }
        if(!params.startTime || !params.endTime) {
          uni.showToast({ title: '请选择动火开始与结束时间', icon: 'none' })
          return false
        }
        if(!params.identificationResult) {
          uni.showToast({ title: '请选择风险辨识结果', icon: 'none' })
          return false
        }
        if(params.level == 2 || params.level ==3 ){
          if(!paramsAnalyzeDataLists[0].createTime){
            uni.showToast({ title: '请选择动火分析时间', icon: 'none' })
            return false
          }
          if(!paramsAnalyzeDataLists[0].analyzeData){
            uni.showToast({ title: '请输入动火分析数据', icon: 'none' })
            return false
          }
          if(!paramsAnalyzeDataLists[0].photo){
            uni.showToast({ title: '请输入分析数据图片', icon: 'none' })
            return false
          }
          if(!paramsAnalyzeDataLists[0].analyst){
            uni.showToast({ title: '请输入分析人', icon: 'none' })
            return false
          }
        }
        for(let index = 0; index < personList.length; index ++) {
          if(!personList[index].workerName) {
            uni.showToast({ title: `请输入动火人信息第${index + 1}项动火人名称`, icon: 'none' })
            return false
          }
          if(!personList[index].certification[0] || !personList[index].certification[0].url) {
            uni.showToast({ title: `请上传动火人信息第${index + 1}项动火人资格证书`, icon: 'none' })
            return false
          }
          if(!personList[index].signature) {
            uni.showToast({ title: `第${index + 1}项动火人未签章`, icon: 'none' })
            return false
          }
        }
        for(let index = 0; index < safeMeasuresList.length; index ++) {
          if(!safeMeasuresList[index].state) {
            if(!safeMeasuresList[index].radioStatus) {
              uni.showToast({ title: `请选择安全措施第${index + 1}项安全状态`, icon: 'none' })
              return false
            }
            if(safeMeasuresList[index].radioStatus != '不适用' && (!safeMeasuresList[index].photo[0] || !safeMeasuresList[index].photo[0].url)) {
              uni.showToast({ title: `请上传安全措施第${index + 1}项照片`, icon: 'none' })
              return false
            }
          }
        }
        if(!params.guardian) {
          uni.showToast({ title: '监护人未签章', icon: 'none' })
          return false
        }
        if(!params.licensor) {
          uni.showToast({ title: '请选择许可人', icon: 'none' })
          return false
        }
        if(!params.signer) {
          uni.showToast({ title: '请选择签发人', icon: 'none' })
          return false
        }
        if((params.level == 2 || params.level == 3) && !params.inCharge) {
          uni.showToast({ title: '请选择分管负责人', icon: 'none' })
          return false
        }
        if(params.level == 3 && !params.mainInCharge) {
          uni.showToast({ title: '请选择主要负责人', icon: 'none' })
          return false
        }
        return true
      },
      routeByUrl: function(url, state = false) {
        console.log({url})
        if(this.allDisabled && !state) return false
        let disable = JSON.stringify(this.disable) 
        uni.navigateTo({ 
          url:url+'&disable='+disable
        })
      }
    }
  }
</script>

<style>
  page {
    background-color: #EFEFEF;
  }
  .u-radio-group {
    align-items: center;
    justify-content: space-around;
  }
  .u-radio__text {
    font-size: 28rpx;
    line-height: 40rpx;
    color: #666666;
  }
  .u-radio-group .u-radio .u-radio__icon-wrap {
    width: 30rpx !important;
    height: 30rpx !important;
  }
</style>

<style lang="scss" scoped>
  .content {
    /deep/ .u-checkbox-group {
      flex-wrap: wrap;
    }
    /deep/ .u-checkbox{
      width: 33%;
    }
    .popup-block {
      width: 600rpx;
      padding: 20rpx;
      .image-list {
        display: flex;
        flex-wrap: wrap;
        .item-image {
          width: 180rpx;
          height: 180rpx;
          border-radius: 10rpx;
          background-color: #CCCCCC;
          margin: 10rpx;
        }
      }
      .popup-title {
        font-size: 30rpx;
        line-height: 42rpx;
        font-weight: 500;
        display: flex;
        // text-align: center;
        .inputcss{
          border: 1rpx solid #BBBBBB;
          border-radius: 8rpx;
          margin-left: 30rpx;
        }
      }
      .button-block {
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
    }
    .wraning-icon {
      color: #FE0303;
      margin-right: 5rpx;
    }
    .list-block {
      background-color: #FFFFFF;
      border-radius: 10rpx;
      .item-blocks {
        display: flex;
        align-items: center;
        justify-content: space-between;
        .item-label {
          font-size: 28rpx;
          line-height: 40rpx;
          color: #333333;
          .wraning-icon {
            color: #FE0303;
            margin-right: 5rpx;
          }
        }
        .item-value {
          font-size: 28rpx;
          line-height: 40rpx;
          color: #999999;
          max-width: 500rpx;
          display: flex;
          align-items: center;
        }
        .image-list {
          max-width: 520rpx;
          display: flex;
          justify-content: flex-end;
          flex-direction: row-reverse;
          flex-wrap: wrap;
          .image {
            width: 156rpx;
            height: 120rpx;
            border-radius: 6rpx;
            background-color: #CCCCCC;
            margin-left: 9rpx;
            // margin-bottom: 20rpx;
          }
          .image:nth-child(3n) {
            margin-left: 0;
          }
        }
      }
      .title-block {
        display: flex;
        align-items: center;
        font-size: 28rpx;
        line-height: 40rpx;
        font-weight: 500;
        color: #333333;
        .title-icon {
          width: 15rpx;
          height: 15rpx;
          border-radius: 100%;
        }
      }
      .item-list {
        position: relative;
        .position-icon {
          width: 36rpx;
          height: 36rpx;
          position: absolute;
          top: 0;
          right: 0;
        }
      }
      .item-block {
        .item-label {
          font-size: 28rpx;
          line-height: 40rpx;
          color: #666666;
          display: flex;
          align-items: center;
          // .wraning-icon {
          //   color: #FE0303;
          //   margin-right: 5rpx;
          // }
        }
        .input-block {
          display: flex;
          align-items: center;
          justify-content: space-between;
          height: 64rpx;
          border: 1rpx solid #BBBBBB;
          border-radius: 8rpx;
          font-size: 28rpx;
          line-height: 40rpx;
          color: #999999;
          .input {
            width: 500rpx;
            font-size: 28rpx;
            line-height: 40rpx;
            color: #333333;
          }
          .placeholder {
            font-size: 28rpx;
            line-height: 40rpx;
            color: #999999;
          }
          .select-value {
            color: #333333;
          }
        }
      }
      .info-block {
        display: flex;
        align-items: center;
        justify-content: space-between;
        .item-label {
          font-size: 28rpx;
          line-height: 40rpx;
          color: #666666;
        }
        .right-block {
          width: 484rpx;
          height: 128rpx;
          border: 1rpx solid #BBBBBB;
          border-radius: 8rpx;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 28rpx;
          color: #666666;
          .image {
            width: 100%;
            height: 100%;
          }
        }
      }
      .image-block {
        display: flex;
        align-items: center;
        .image-title {
          font-size: 28rpx;
          line-height: 40rpx;
          color: #666666;
          margin-right: 20rpx;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
      .button-block {
        display: flex;
        justify-content: center;
        .button {
          width: 674rpx;
          height: 80rpx;
          border-radius: 10rpx;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 30rpx;
          color: #FFFFFF;
          background-color: #03B3FD;
        }
        .button::after {
          border: none;
        }
      }
    }
    .button-block {
      display: flex;
      align-items: center;
      justify-content: space-between;
      .button-cancel {
        width: 334rpx;
        height: 64rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 26rpx;
        color: #FFFFFF;
        border-radius: 8rpx;
        background-color: #BBBBBB;
        box-shadow: 7rpx 9rpx 15rpx rgba(51, 51, 51, 0.27);
      }
      .button-cancel::after {
        border: none;
      }
      .button-submit {
        @extend .button-cancel;
        background-color: #03B3FD;
      }
      .button-submit::after {
        border: none;
      }
      .button-success {
        width: 668rpx;
        @extend .button-cancel;
        background-color: #19BE6B;
      }
      .button-success::after {
        border: none;
      }
    }
    .text-area {
      width: 500rpx;
      height: 100rpx;
      border-radius: 10rpx;
      border: 1rpx solid #EFEFEF;
      padding: 20rpx;
      font-size: 28rpx;
      line-height: 40rpx;
      color: #333333;
    }
    .text-area-placeholder {
      font-size: 28rpx;
      line-height: 40rpx;
      color: #999999;
    }
    .toast-block {
      background-color: #FFFFFF;
      width: 500rpx;
      min-height: 200rpx;
      .toast {
        font-size: 28rpx;
        line-height: 40rpx;
        color: #333333;
        text-indent: 48rpx;
      }
    }
    .radio-block {
      .input-block {
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 26rpx;
        line-height: 36rpx;
        color: #333333;
        .input {
          font-size: 26rpx;
          line-height: 36rpx;
          color: #333333;
        }
        .placeholder {
          font-size: 26rpx;
          line-height: 36rpx;
          color: #999999;
        }
      }
    }
  }
</style>
